package com.mycat.tencent.entity.request;


import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.alipay.api.internal.util.StringUtils;
import com.mycat.exception.PaymentException;

/**
 * 微信支付之【统一下单参数】
 *
 * @author roger.
 * @email luojie@yzworld.cn
 * @date 2016/9/7
 */
public class WxUnifiedorderParams implements Serializable {
	private static final long serialVersionUID = -8891885774911422578L;
	// 应用ID  是
    private String appid;
    // 商户号  是
    private String mch_id;
    // 设备号  否
    private String device_info;
    // 随机字符串   是
    private String nonce_str;
    // 签名  是
    private String sign;
    // 商品描述 是
    private String body;
    // 商品详情  否
    private String detail;
    // 附加数据  否
    private String attach;
    // 商户订单号  是
    private String out_trade_no;
    // 货币类型  否
    private String fee_type;
    // 总金额(分)    是
    private Integer total_fee;
    // 终端IP    是
    private String spbill_create_ip;
    // 交易起始时间(yyyyMMddHHmmss)  否
    private String time_start;
    // 交易结束时间(yyyyMMddHHmmss)  否
    private String time_expire;
    // 商品标记   否
    private String goods_tag;
    // 通知地址(接收微信支付异步通知回调地址)   是
    private String notify_url;
    // 交易类型	  是
    private String trade_type;
    // 商品ID  否
    private String product_id;
    // 指定支付方式  否
    private String limit_pay;
    // 用户标识  否
    private String openid;

    public Map<String,Object> toMap() throws Exception{
        Map<String,Object> map = new HashMap<>();
        if(StringUtils.isEmpty(this.getAppid())){
           throw new PaymentException("应用ID不能为空");
        }
        map.put("appid",this.getAppid());
        if(StringUtils.isEmpty(this.getMch_id())){
            throw new PaymentException("商户号不能为空");
        }
        map.put("mch_id",this.getMch_id());
        if(!StringUtils.isEmpty(this.getDevice_info())){
            map.put("device_info",this.getDevice_info());
        }
        if(StringUtils.isEmpty(this.getNonce_str())){
            throw new PaymentException("随机字符串不能为空");
        }
        map.put("nonce_str",this.getMch_id());
        if(StringUtils.isEmpty(this.getBody())){
            throw new PaymentException("商品描述不能为空");
        }
        map.put("body",this.getMch_id());
        if(!StringUtils.isEmpty(this.getDetail())){
            map.put("detail",this.getDetail());
        }
        if(!StringUtils.isEmpty(this.getAttach())){
            map.put("attach",this.getAttach());
        }
        if(StringUtils.isEmpty(this.getOut_trade_no())){
            throw new PaymentException("商户订单号不能为空");
        }
        map.put("out_trade_no",this.getOut_trade_no());
        if(!StringUtils.isEmpty(this.getFee_type())){
            map.put("fee_type",this.getFee_type());
        }
        if(null == this.getTotal_fee()){
            throw new PaymentException("总金额不能为空");
        }
        map.put("total_fee",String.valueOf(this.getTotal_fee()));
        if(StringUtils.isEmpty(this.getSpbill_create_ip())){
            throw new PaymentException("终端IP不能为空");
        }
        map.put("spbill_create_ip",this.getSpbill_create_ip());
        if(!StringUtils.isEmpty(this.getTime_start())){
            map.put("time_start",this.getTime_start());
        }
        if(!StringUtils.isEmpty(this.getTime_expire())){
            map.put("time_expire",this.getTime_expire());
        }
        if(!StringUtils.isEmpty(this.getGoods_tag())){
            map.put("goods_tag",this.getGoods_tag());
        }
        if(StringUtils.isEmpty(this.getNotify_url())){
            throw new PaymentException("通知地址不能为空");
        }
        map.put("notify_url",this.getNotify_url());
        if(StringUtils.isEmpty(this.getTrade_type())){
            throw new PaymentException("交易类型不能为空");
        }
        map.put("trade_type",this.getTrade_type());
        if(!StringUtils.isEmpty(this.getLimit_pay())){
            map.put("limit_pay",this.getLimit_pay());
        }
        if(!StringUtils.isEmpty(this.getProduct_id())){
            map.put("product_id",this.getProduct_id());
        }
        if(!StringUtils.isEmpty(this.getOpenid())){
            map.put("openid",this.getOpenid());
        }
        return map;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getMch_id() {
        return mch_id;
    }

    public void setMch_id(String mch_id) {
        this.mch_id = mch_id;
    }

    public String getDevice_info() {
        return device_info;
    }

    public void setDevice_info(String device_info) {
        this.device_info = device_info;
    }

    public String getNonce_str() {
        return nonce_str;
    }

    public void setNonce_str(String nonce_str) {
        this.nonce_str = nonce_str;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getAttach() {
        return attach;
    }

    public void setAttach(String attach) {
        this.attach = attach;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }

    public String getFee_type() {
        return fee_type;
    }

    public void setFee_type(String fee_type) {
        this.fee_type = fee_type;
    }

    public Integer getTotal_fee() {
        return total_fee;
    }

    public void setTotal_fee(Integer total_fee) {
        this.total_fee = total_fee;
    }

    public String getSpbill_create_ip() {
        return spbill_create_ip;
    }

    public void setSpbill_create_ip(String spbill_create_ip) {
        this.spbill_create_ip = spbill_create_ip;
    }

    public String getTime_start() {
        return time_start;
    }

    public void setTime_start(String time_start) {
        this.time_start = time_start;
    }

    public String getTime_expire() {
        return time_expire;
    }

    public void setTime_expire(String time_expire) {
        this.time_expire = time_expire;
    }

    public String getGoods_tag() {
        return goods_tag;
    }

    public void setGoods_tag(String goods_tag) {
        this.goods_tag = goods_tag;
    }

    public String getNotify_url() {
        return notify_url;
    }

    public void setNotify_url(String notify_url) {
        this.notify_url = notify_url;
    }

    public String getTrade_type() {
        return trade_type;
    }

    public void setTrade_type(String trade_type) {
        this.trade_type = trade_type;
    }

    public String getProduct_id() {
        return product_id;
    }

    public void setProduct_id(String product_id) {
        this.product_id = product_id;
    }

    public String getLimit_pay() {
        return limit_pay;
    }

    public void setLimit_pay(String limit_pay) {
        this.limit_pay = limit_pay;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }
}
